//
//  HitTestVC.m
//  InduceTool
//
//  Created by 冯琰琰 on 2022/1/9.
//  Copyright © 2022 魏延龙. All rights reserved.
//

#import "HitTestVC.h"
#import "HitViewA.h"
#import "HitViewB.h"
#import "HitViewC.h"
#import "HitViewD.h"
#import "HitViewE.h"
#import "HitTestControlA.h"

@interface HitTestVC ()

@end

@implementation HitTestVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    
    
    HitViewA *viewA = [[HitViewA alloc] initWithFrame:CGRectMake(10, 100, 300, 500)];
    viewA.backgroundColor = [UIColor redColor];
    [self.view addSubview:viewA];
    
    
    HitViewB *viewB = [[HitViewB alloc] initWithFrame:CGRectMake(10, 20, 200, 50)];
    viewB.backgroundColor = [UIColor blueColor];
    [viewA addSubview:viewB];
    
    HitViewC *viewC = [[HitViewC alloc] initWithFrame:CGRectMake(10, 100, 200, 300)];
    viewC.backgroundColor = [UIColor grayColor];
//    viewC.userInteractionEnabled = NO;
    [viewA addSubview:viewC];
    
    HitViewD *viewD = [[HitViewD alloc] initWithFrame:CGRectMake(10, 20, 180, 50)];
    viewD.backgroundColor = [UIColor purpleColor];
    [viewC addSubview:viewD];
    
    HitViewE *viewE = [[HitViewE alloc] initWithFrame:CGRectMake(10, 100, 180, 50)];
    viewE.backgroundColor = [UIColor cyanColor];
    [viewC addSubview:viewE];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    [viewA addGestureRecognizer:tap];
    
    HitTestControlA *controlA = [[HitTestControlA alloc] initWithFrame:CGRectMake(10, 0, 200, 88)];
    controlA.backgroundColor = [UIColor orangeColor];
    [viewD addSubview:controlA];
    [controlA addTarget:self action:@selector(controlActionA) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void) controlActionA{
    NSLog(@"controlActionA");
}
-(void)tapAction {
    NSLog(@"tapAction");
}
/*
 1. 系统通过 hitTest:withEvent: 方法沿视图层级树从底向上（从根视图开始）从后向前（从逻辑上更靠近屏幕的视图开始）进行遍历，最终返回一个适合响应触摸事件的 View。
 2. 原生触摸事件从 Hit-Testing 返回的 View 开始，沿着响应链从上向下进行传递。
 链接：https://juejin.cn/post/6844903905080410125
 */


@end
